<template>
	<view class="u-page">
		<u-cell-group>
			<u-cell
				    title="当前工程:"
				    value=""
				    :label="currentbuild.Name"
					@click="show=true"
					:isLink="true" 
				></u-cell>
		<!-- 		<u-button
				    text="默认按钮"
				    size="normal"
				    type="info"
					@click="click"
				></u-button> -->
				<u-gap height="20"></u-gap>
				<u-button type="primary" v-if="buildlist.length!=0"  @click="gosafe">填报安全交底</u-button>
				<u-gap height="20"></u-gap>
			<!-- 	<u-divider text=""></u-divider> -->
				<u-button type="success" v-if="buildlist.length!=0"  @click="godaily">填报工程日志</u-button>
				<u-gap height="20"></u-gap>
				<!-- 	<u-divider text=""></u-divider> -->
					<u-button type="warning"  @click="goimage">查看已填报</u-button>
				<u-picker ref="uPicker" :show="show" :columns="columns"  @confirm="confirm" @change="changeHandler"></u-picker>
				<u--text v-if="buildlist.length==0">您暂时没有工程需要上传</u--text>
		</u-cell-group>
		</view>
</template>

<script>
	import {
		getbuildsafebyid,
		getbuilddailybyid,
		getbuildlist
		
	} from '@/common/api.js'
	export default {
		data() {
			return {
				currentbuild:{Name:""},
				user:{},
				columns:[[]],
				show:false,
				buildlist:[]
			}
		},
		onLoad(option) {
			console.log(uni.getStorageSync("$userinfo"))
			let user = JSON.parse(uni.getStorageSync("$userinfo"))
			this.user = user
			this.getlist()
		},

		methods: {
			click() {
				console.log('Cell is clicked.');
			},
			getlist() {
				// let querytype = this.$route.query.querytype
				let para = {
					Parameters:[],
				}
			
					para.Parameters.push({
						FieldName: "ProjManager",
						ConditionalType: "Equal",
						FieldValue: this.user.Name
					});
					para.Parameters.push({
						FieldName: "Status",
						ConditionalType: "Equal",
						FieldValue:"已派工"
					});
					para.OrderBys=["CreateTime desc"]
				
			
				// if (querytype == "日志") {
			
			
				// }
				getbuildlist(para).then(res => {
					this.buildlist = res.data
					this.columns=[[]]
					for(var i=0;i<this.buildlist.length;i++)
					{
						this.columns[0].push(this.buildlist[i].Name)
					}
					if(this.buildlist.length>0)
					this.currentbuild = this.buildlist[0]
				})
			},
			gosafe()
			{
				uni.navigateTo({
					url:"/pages/index/buildsafedetail?buildid="+this.currentbuild.Id
				})
			},
			godaily()
			{
				uni.navigateTo({
					url:"/pages/index/builddailydetail?buildid="+this.currentbuild.Id
				})
			},
			goimage()
			{
				uni.switchTab({
					url:"/pages/index/buildimages"
				})
			},
			            changeHandler(e) {
			                const {
			                    columnIndex,
			                    value,
			                    values, // values为当前变化列的数组内容
			                    index,
								// 微信小程序无法将picker实例传出来，只能通过ref操作
			                    picker = this.$refs.uPicker
			                } = e
			                // 当第一列值发生变化时，变化第二列(后一列)对应的选项
			                // if (columnIndex === 0) {
			                //     // picker为选择器this实例，变化第二列对应的选项
			                //     picker.setColumnValues(1, this.columnData[index])
			                // }
			            },
						// 回调参数为包含columnIndex、value、values
						confirm(e) {
			                console.log('confirm', e)
			                this.show = false
						}
					
		}
	}
</script>

<style lang="scss">
	.cell-page {
		padding-bottom: 20px;
	}

	.cell-box {
		&__title {
			font-size: 14px;
			color: rgb(143, 156, 162);
			margin: 20px 0px 0px 15px;
		}

		&__block {
			// background-color: #fff;
			margin-top: 20px;
		}
	}

	.u-page {
		padding: 0;

		&__item {

			&__title {
				color: $u-tips-color;
				background-color: $u-bg-color;
				padding: 15px;
				font-size: 15px;

				&__slot-title {
					color: $u-primary;
					font-size: 14px;
				}
			}
		}
	}

	.u-slot-title {
		@include flex;
		flex-direction: row;
		align-items: center;
	}

	.u-cell-text {
		font-size: 15px;
		line-height: 22px;
		color: #303133;
		margin-right: 5px;
	}

	.u-slot-value {
		line-height: 17px;
		text-align: center;
		font-size: 10px;
		padding: 0 5px;
		height: 17px;
		color: #FFFFFF;
		border-radius: 100px;
		background-color: #f56c6c;
	}
</style>